package service

import (
	"content-sharing_0929/internal/model"
	"content-sharing_0929/internal/params"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddPost(c *gin.Context) {
	var req params.AddPostForm

	err := c.ShouldBindJSON(&req)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    100000,
			"message": "验证失败",
			"data":    "",
		})
		return
	}

	var sharing model.Sharing

	sharing = model.Sharing{
		UserId:   req.UserId,
		ImageUrl: req.ImageUrl,
		Content:  req.Content,
		Status:   0,
	}

	err = sharing.AddSharing()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    100000,
			"message": "发布失败",
			"data":    err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "发布成功",
		"data":    sharing.Id,
	})

}
